//
//  ZSCTTableViewController.m
//  ZhuShou
//
//  Created by Dejun Liu on 15/10/30.
//  Copyright © 2015年 jw. All rights reserved.
//

#import "ZSCTTableViewController.h"
#import "ZSTwoTableViewCell.h"

@interface ZSCTTableViewController ()

@property (nonatomic,strong) NSArray *list;

@end

@implementation ZSCTTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.list = @[@"灯光",
                  @"电视机",
                  @"空调",
                  @"窗帘",
                  @"插座",
                  @"门锁"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ZSTwoTableViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
    

    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestData:)];
    self.tableView.header = header;
    
    MJRefreshAutoStateFooter *footer = [MJRefreshAutoStateFooter footerWithRefreshingTarget:self refreshingAction:@selector(requestData:)];
    self.tableView.footer = footer;
    
    [self.tableView.header beginRefreshing];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"Cell";
    ZSTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    cell.df_titleLabel.text = [self.list objectAtIndex:indexPath.row];
    cell.df_imageView.image = [UIImage imageNamed:@"menu_icon_tv"];
    
    int value = arc4random() % 2;
    if (value) {
        cell.df_switchView.hidden = YES;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else
    {
        cell.df_switchView.hidden = NO;
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 44.0f;
//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark RequestData

- (void)requestData:(MJRefreshHeader *) commponent
{
    [self.tableView.header endRefreshing];
    [self.tableView.footer endRefreshing];
    [self.tableView.footer noticeNoMoreData];
}

@end
